class Solution:
    def minDeletions(self, s: str) -> int:
        counter = {}
        for string in s:
            if string not in counter:
                counter[string] = 0
            counter[string] += 1
        array = [0 for _ in range(10**5)]
        for val in counter.values():
            array[val] += 1
        res = 0
        for i in range(len(array) - 1, 0, -1):
            delete = 0
            if array[i] > 1:
                delete = array[i] - 1
            array[i - 1] += delete
            res += delete

        return res
